import requests


class IHRMApi:
    # 登录接口
    @classmethod
    def login_api(cls, login_body):
        login_url = "http://ihrm2-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

    # 添加员工接口
    @classmethod
    def add_api(cls, token, body):
        url = "http://ihrm2-test.itheima.net/api/sys/user"
        headers = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.post(url=url, headers=headers, json=body)
        return resp

    # 查询员工接口
    @classmethod
    def query_api(cls, token, id):
        url = f"http://ihrm2-test.itheima.net/api/sys/user/{id}"
        headers = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.get(url=url, headers=headers)
        return resp

    # 修改员工接口
    @classmethod
    def change_api(cls, token, id, body):
        url = f"http://ihrm2-test.itheima.net/api/sys/user/{id}"
        headers = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.put(url=url, headers=headers, json=body)
        return resp

    # 删除员工接口
    @classmethod
    def del_api(cls, token, id):
        url = f"http://ihrm2-test.itheima.net/api/sys/user/{id}"
        headers = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.delete(url=url, headers=headers)
        return resp
